package me.jiatao.hilt.scopes

import android.util.Log
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.FragmentComponent
import dagger.hilt.android.scopes.FragmentScoped

class FragmentClassA {
    fun hello() {
        Log.e("FragmentClassA", "------ FragmentClassA hello  ------")
    }
}

class FragmentClassB(private val appClassA: AppClassA) {
    fun hello() {
        appClassA.hello()
        Log.e("FragmentClassB", "------ FragmentClassB hello  ------")
    }
}

class FragmentClassC(private val appClassA: AppClassA, private val activityClassA: ActivityClassA) {
    fun hello() {
        appClassA.hello()
        activityClassA.hello()
        Log.e("FragmentClassC", "------ FragmentClassC hello  ------")
    }
}


@Module
@InstallIn(FragmentComponent::class)
class FragmentScopes {

    @FragmentScoped
    @Provides
    fun provideFragmentClassA(): FragmentClassA {
        return FragmentClassA()
    }

    @FragmentScoped
    @Provides
    fun provideFragmentClassB(appClassA: AppClassA): FragmentClassB {
        return FragmentClassB(appClassA)
    }

    @FragmentScoped
    @Provides
    fun provideFragmentClassC(
        appClassA: AppClassA,
        activityClassA: ActivityClassA
    ): FragmentClassC {
        return FragmentClassC(appClassA, activityClassA)
    }
}